﻿@inject IStringLocalizer<TablesEditInjectDataService> Localizer
@inject IStringLocalizer<Foo> LocalizerFoo
@inject IOptionsMonitor<WebsiteOptions> WebsiteOption

<p id="anchor6">
    @((MarkupString)Localizer["TablesEditInjectDataServiceDescription"].Value)
    <ul class="ul-demo mb-3">
        <li><code>OnAddAsync</code></li>
        <li><code>OnDeleteAsync</code></li>
        <li><code>OnSaveAsync</code></li>
        <li><code>OnQueryAsync</code></li>
    </ul>
    <div class="mb-3">@Localizer["TablesEditInjectDataServiceTips1"] <a href="@DataServiceUrl" target="_blank">@Localizer["TablesEditInjectDataServiceTips2"]</a></div>
    <b>@Localizer["TablesEditInjectDataServiceTips3"]</b>
    <div class="mt-1">@Localizer["TablesEditInjectDataServiceTips4"]</div>
</p>
<Pre class="no-highlight my-3">services.AddTableDemoDataService();</Pre>
<Table TItem="Foo"
        IsPagination="true" PageItemsSource="@PageItemsSource"
        IsStriped="true" IsBordered="true" IsMultipleSelect="true" AutoGenerateColumns="true"
        ShowToolbar="true" ShowExtendButtons="true" ShowSkeleton="true">
    <TableColumns>
        <TableColumn @bind-Field="@context.Hobby" Items="@Hobbys" />
    </TableColumns>
</Table>

@code {
    private static IEnumerable<int> PageItemsSource => new int[] { 4, 10, 20 };

    [NotNull]
    private IEnumerable<SelectedItem>? Hobbys { get; set; }

    [NotNull]
    private List<Foo>? Items { get; set; }

    private string DataServiceUrl => $"{WebsiteOption.CurrentValue.BootstrapBlazorLink}/wikis/Table%20%E7%BB%84%E4%BB%B6%E6%95%B0%E6%8D%AE%E6%9C%8D%E5%8A%A1%E4%BB%8B%E7%BB%8D?sort_id=3207977";

    /// <summary>
    /// OnInitialized 方法
    /// </summary>
    protected override void OnInitialized()
    {
        base.OnInitialized();

        Hobbys = Foo.GenerateHobbys(LocalizerFoo);
        Items = Foo.GenerateFoo(LocalizerFoo);
    }
}
